package org.fang.controller;

import org.fang.common.PlatformResult;
import org.fang.pojo.CloudUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestClientException;
import org.springframework.web.client.RestTemplate;
/**
 * @Author forsake
 * @Description 当我们开启ribbon，restTemplate使用@LoadBalanced注解修饰，服务间的调用方式就只能用实例名称，而不能使用http://localhost:8001，
 * 所以下面的调用方式不生效了，需要注释@LoadBalanced
 * @Date 0:07 2022/11/29
 **/  
@RestController
public class UserConsumerController {
    @Autowired
    RestTemplate restTemplate;
    public static final String URL_PREFIX = "http://localhost:8001";
    @RequestMapping("/consumer/cloudUser/add")
    public PlatformResult add(@RequestBody CloudUser user) {
        return restTemplate.postForObject(URL_PREFIX + "/cloudUser/add", user, PlatformResult.class);
    }
    @RequestMapping("/consumer/cloudUser/queryById/{id}")
    public PlatformResult queryById(@PathVariable("id") String id) {
        return restTemplate.postForObject(URL_PREFIX + "/cloudUser/queryById/" + id,null, PlatformResult.class);
    }
}
